﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.Identity.Client;
using Newtonsoft.Json;
using SenFangKaoHe_MVC.Models.Entity;
using SenFangKaoHe_MVC.Models.ViewModel;
using SenFangKaoHe_MVC.Services;
using SqlSugar;
using System.Diagnostics;

namespace SenFangKaoHe_MVC.Controllers
{
    public class LianXiController : Controller
    {
        private readonly SqlSugarClient db;
        public LianXiController(SqlSugarClient db)
        {
            this.db = db;
        }
        public async Task<IActionResult> Index()
        {
            List<tiku> tks = await new TiKuServices(db).getTiKus();
            return View(tks);
        }

        public async Task<IActionResult> LianXi(int id)
        {
            TempTiKuKaoTi tmpTiKuKaoTi = new TempTiKuKaoTi();
            tiku tk = await new TiKuServices(db).getTiKu(id);
            List<tikukaoti> tkkts = await new KaoShiServices(db).getKaoTi(id);
            tmpTiKuKaoTi.tiku = tk;
            tmpTiKuKaoTi.tikukaoti = tkkts;
            return View(tmpTiKuKaoTi);
        }

        public async Task<IActionResult> MoNi(int id)
        {
            tiku tk = await new TiKuServices(db).getTiKu(id);
            Debug.WriteLine(JsonConvert.SerializeObject(tk));
            TempShiJuan tmp_sj = new TempShiJuan();
            
                var tkid = id;
                int tks = tkid;//题库ID 

                int[] txs = { 1, 2, 3, 4 };
                int[] tls = { 0,10,10,10 };
                int[] fzs = { 0,3,4,3 };

                List<TempShiJuanKaoTi> selectkt = await new KaoShiServices(db).getMoNiKaoTi(id, txs, tls, fzs);
                tmp_sj.Id = id;
                tmp_sj.ShiTi = selectkt;
                tmp_sj.KaoHeMingCheng = tk.tikuming+"模拟考核";
                tmp_sj.XingMing = "模拟用户";
                tmp_sj.YiDaTiShu = 0;
                tmp_sj.KaoHeFanWei = tk.tikuming+"";
                Debug.WriteLine(JsonConvert.SerializeObject(tmp_sj));
           
            return View(tmp_sj);
        }

        public async Task<TempShiJuan> getMoNiCuoTi(string tkmc, string ctids, string ctdas, int fenzhi, int chengji)
        {
            return await new LianXiServices(db).getMoNiCuoTi(tkmc, ctids, ctdas, fenzhi, chengji);
        }

        }
}
